<!DOCTYPE html>
<html lang="zh-CN">

  <head>
  <meta charset="utf-8">
  <meta name="author" content="zchengsite, 1451426471@qq.com" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  
  
  <title>Android GridView控件   | EMV.COOL</title>

  
    <link rel="apple-touch-icon" href="/images/favicon.png">
    <link rel="icon" href="/images/favicon.png">
  

  <!-- Raleway-Font -->
  <link href="https://fonts.googleapis.com/css?family=Raleway&display=swap" rel="stylesheet">

  <!-- hexo site css -->
  
<link rel="stylesheet" href="/css/base.css">
<link rel="stylesheet" href="/iconfont/iconfont.css">
<link rel="stylesheet" href="/css/github-markdown.css">
<link rel="stylesheet" href="/css/highlight.css">


  <!-- jquery3.3.1 -->
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

  <!-- fancybox -->
  <link href="https://cdn.bootcss.com/fancybox/3.5.2/jquery.fancybox.min.css" rel="stylesheet">
  <script async src="https://cdn.bootcss.com/fancybox/3.5.2/jquery.fancybox.min.js"></script>
  
<script src="/js/fancybox.js"></script>


  
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-144519052-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-144519052-1');
    </script>
  

   
    <meta name="keywords" content="android, GridView,emv,blog,victor,victorlong,龙熙应,longxiying,emv.cool,aid,sale,void,visa,master,android,QuickChip,tag,emvtag,paypass,paywave,dpas,contact,contactless,card,pos,pin,pin-blocks,atrs,hsm,key,dukpt,3des,des,sm4,sm3,apdu,tsys,Hexo,ilovejj">
    

<meta name="generator" content="Hexo 5.3.0"><link rel="alternate" href="/atom.xml" title="EMV.COOL" type="application/atom+xml">
</head>


  <body>
    <div id="app">
      <div class="header">
  <div class="avatar">
    <a href="/">
      <!-- 头像取消懒加载，添加no-lazy -->
      
        <img src="/images/avatar.png" alt="">
      
    </a>
    <div class="nickname"><a href="/">EMV.COOL</a></div>
  </div>
  <div class="navbar">
    <ul>
      
        <li class="nav-item" data-path="/">
          <a href="/">Home</a>
        </li>
      
        <li class="nav-item" data-path="/archives/">
          <a href="/archives/">Archives</a>
        </li>
      
        <li class="nav-item" data-path="/tags/">
          <a href="/tags/">Tags</a>
        </li>
      
        <li class="nav-item" data-path="/friends/">
          <a href="/friends/">Friends</a>
        </li>
      
        <li class="nav-item" data-path="/about/">
          <a href="/about/">About</a>
        </li>
      
    </ul>
  </div>
</div>


<script src="/js/activeNav.js"></script>



      <div class="flex-container">
        <!-- 文章详情页，展示文章具体内容，url形式：https://yoursite/文章标题/ -->
<!-- 同时为「标签tag」，「朋友friend」，「分类categories」，「关于about」页面的承载页面，具体展示取决于page.type -->



  

  

  

  
  <!-- 文章内容页 url形式：https://yoursite/文章标题/ -->
  <div class="container post-details" id="post-details">
    <div class="post-content">
      <div class="post-title">Android GridView控件</div>
      <div class="post-attach">
        <span class="post-pubtime">
          <i class="iconfont icon-updatetime" title="Update time"></i>
          2020-12-23
        </span>
        
              <span class="post-tags">
                <i class="iconfont icon-tags" title="Tags"></i>
                
                <span class="span--tag">
                  <a href="/tags/Android/" title="Android">
                    <b>#</b> Android
                  </a>
                </span>
                
                <span class="span--tag">
                  <a href="/tags/GridView/" title="GridView">
                    <b>#</b> GridView
                  </a>
                </span>
                
              </span>
          
      </div>
      <div class="markdown-body">
        <ul>
<li><strong>home_activity.xml：</strong><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;RelativeLayout xmlns:android&#x3D;&quot;http:&#x2F;&#x2F;schemas.android.com&#x2F;apk&#x2F;res&#x2F;android&quot;</span><br><span class="line">    android:layout_width&#x3D;&quot;match_parent&quot;</span><br><span class="line">    android:layout_height&#x3D;&quot;match_parent&quot;</span><br><span class="line">    android:background&#x3D;&quot;#000000&quot; &gt;</span><br><span class="line">    </span><br><span class="line">    &lt;GridView</span><br><span class="line">        android:id&#x3D;&quot;@+id&#x2F;gridView1&quot;</span><br><span class="line">        android:layout_width&#x3D;&quot;match_parent&quot;</span><br><span class="line">        android:layout_height&#x3D;&quot;match_parent&quot;&gt;</span><br><span class="line">    &lt;&#x2F;GridView&gt;</span><br><span class="line"></span><br><span class="line">&lt;&#x2F;RelativeLayout&gt;</span><br></pre></td></tr></table></figure></li>
<li><strong>HomeActivity.java</strong></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">package cccc.cccc;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line">import com.example.gridviewstudy.R;</span><br><span class="line">import android.annotation.SuppressLint;</span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.content.pm.ApplicationInfo;</span><br><span class="line">import android.content.pm.PackageInfo;</span><br><span class="line">import android.content.pm.PackageManager;</span><br><span class="line">import android.os.Bundle;</span><br><span class="line">import android.view.Window;</span><br><span class="line">import android.view.WindowManager;</span><br><span class="line">import android.widget.GridView;</span><br><span class="line"></span><br><span class="line">public class HomeActivity extends Activity &#123;</span><br><span class="line">	</span><br><span class="line">	private GridView mGridView;</span><br><span class="line">	private List&lt;AppInfo&gt; appInfos;</span><br><span class="line">	</span><br><span class="line">	@SuppressLint(&quot;InlinedApi&quot;)</span><br><span class="line">	@Override</span><br><span class="line">	protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">		super.onCreate(savedInstanceState);</span><br><span class="line">		this.requestWindowFeature(Window.FEATURE_NO_TITLE);&#x2F;&#x2F;去掉标题栏  </span><br><span class="line">        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); &#x2F;&#x2F;透明状态栏  </span><br><span class="line">        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);&#x2F;&#x2F;透明导航栏  </span><br><span class="line">		setContentView(R.layout.home_activity);</span><br><span class="line">		mGridView &#x3D; (GridView)this.findViewById(R.id.gridView1);</span><br><span class="line">		getData();</span><br><span class="line">		mGridView.setNumColumns(6);</span><br><span class="line">		GridViewAdapter adapter &#x3D; new GridViewAdapter(appInfos,this);</span><br><span class="line">		mGridView.setAdapter(adapter);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	private void getData() &#123;</span><br><span class="line">		PackageManager packageManager &#x3D; this.getPackageManager();</span><br><span class="line">		List&lt;PackageInfo&gt; packageInfos &#x3D; packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);</span><br><span class="line">		appInfos &#x3D; new ArrayList&lt;AppInfo&gt;();</span><br><span class="line">		for(PackageInfo packageInfo:packageInfos)&#123;</span><br><span class="line">			AppInfo appInfo &#x3D; new AppInfo();</span><br><span class="line">			appInfo.setAppName(packageInfo.applicationInfo.loadLabel(packageManager).toString());</span><br><span class="line">			appInfo.setAppPackage(packageInfo.packageName);</span><br><span class="line">			appInfo.setAppVersion(packageInfo.versionName);</span><br><span class="line">			appInfo.setDrawable(packageInfo.applicationInfo.loadIcon(packageManager));</span><br><span class="line">			appInfo.setUserApp(filterApp(packageInfo.applicationInfo));</span><br><span class="line">			if(appInfo.isUserApp())&#123;</span><br><span class="line">				appInfos.add(appInfo);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	public boolean filterApp(ApplicationInfo info) &#123;</span><br><span class="line">		if ((info.flags &amp; ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) !&#x3D; 0) &#123;</span><br><span class="line">			return true;</span><br><span class="line">		&#125; else if ((info.flags &amp; ApplicationInfo.FLAG_SYSTEM) &#x3D;&#x3D; 0) &#123;</span><br><span class="line">			return true;</span><br><span class="line">		&#125;</span><br><span class="line">		return false;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><strong>AppInfo.java</strong></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">package cccc.cccc;</span><br><span class="line"></span><br><span class="line">import android.graphics.drawable.Drawable;</span><br><span class="line"></span><br><span class="line">public class AppInfo &#123;</span><br><span class="line">	private String appName;    &#x2F;&#x2F; 获取应用程序的名称，不是包名，而是清单文件中的labelname</span><br><span class="line">	private String appVersion; &#x2F;&#x2F; 获取应用程序的版本号码</span><br><span class="line">	private Drawable drawable; &#x2F;&#x2F; 获取应用程序的快捷方式图标</span><br><span class="line">	private boolean isUserApp; &#x2F;&#x2F; 获取应用程序是否是第三方应用程序</span><br><span class="line">	private String appPackage; &#x2F;&#x2F;给一同程序设置包名</span><br><span class="line">	public String getAppName() &#123;</span><br><span class="line">		return appName;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setAppName(String appName) &#123;</span><br><span class="line">		this.appName &#x3D; appName;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getAppVersion() &#123;</span><br><span class="line">		return appVersion;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setAppVersion(String appVersion) &#123;</span><br><span class="line">		this.appVersion &#x3D; appVersion;</span><br><span class="line">	&#125;</span><br><span class="line">	public Drawable getDrawable() &#123;</span><br><span class="line">		return drawable;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setDrawable(Drawable drawable) &#123;</span><br><span class="line">		this.drawable &#x3D; drawable;</span><br><span class="line">	&#125;</span><br><span class="line">	public boolean isUserApp() &#123;</span><br><span class="line">		return isUserApp;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setUserApp(boolean isUserApp) &#123;</span><br><span class="line">		this.isUserApp &#x3D; isUserApp;</span><br><span class="line">	&#125;</span><br><span class="line">	public String getAppPackage() &#123;</span><br><span class="line">		return appPackage;</span><br><span class="line">	&#125;</span><br><span class="line">	public void setAppPackage(String appPackage) &#123;</span><br><span class="line">		this.appPackage &#x3D; appPackage;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li><strong>GridViewAdapter.java</strong></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line">package cccc.cccc;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import com.example.gridviewstudy.R;</span><br><span class="line"></span><br><span class="line">import android.annotation.SuppressLint;</span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.view.LayoutInflater;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.view.View.OnClickListener;</span><br><span class="line">import android.view.ViewGroup;</span><br><span class="line">import android.widget.BaseAdapter;</span><br><span class="line">import android.widget.ImageView;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line"></span><br><span class="line">public class GridViewAdapter extends BaseAdapter &#123;</span><br><span class="line">	</span><br><span class="line">	private List&lt;AppInfo&gt; appInfos &#x3D; null;</span><br><span class="line">	private Context mContext &#x3D; null;</span><br><span class="line">	private LayoutInflater inflater &#x3D; null;  </span><br><span class="line">	</span><br><span class="line">	public GridViewAdapter(List&lt;AppInfo&gt; appInfos,Context context) &#123;</span><br><span class="line">		this.appInfos &#x3D; appInfos;</span><br><span class="line">		this.mContext &#x3D; context;</span><br><span class="line">		inflater &#x3D; LayoutInflater.from(mContext);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public int getCount() &#123;</span><br><span class="line">		return appInfos.size();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public Object getItem(int position) &#123;</span><br><span class="line">		return null;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public long getItemId(int position) &#123;</span><br><span class="line">		return 0;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@SuppressLint(&quot;InflateParams&quot;)</span><br><span class="line">	@Override</span><br><span class="line">	public View getView(final int position, View convertView, ViewGroup parent) &#123;</span><br><span class="line">		Holder holder;</span><br><span class="line">		if(convertView &#x3D;&#x3D; null)&#123;</span><br><span class="line">			convertView &#x3D; inflater.inflate(R.layout.gridview_item,null);</span><br><span class="line">			holder &#x3D; new Holder();</span><br><span class="line">			holder.icon &#x3D; (ImageView)convertView.findViewById(R.id.imageView1);</span><br><span class="line">			holder.name &#x3D; (TextView)convertView.findViewById(R.id.textview1);</span><br><span class="line">			convertView.setTag(holder);</span><br><span class="line">		&#125;else&#123;</span><br><span class="line">			holder &#x3D; (Holder)convertView.getTag();</span><br><span class="line">		&#125;</span><br><span class="line">		holder.icon.setImageDrawable(appInfos.get(position).getDrawable());</span><br><span class="line">		holder.name.setText(appInfos.get(position).getAppName());</span><br><span class="line">		convertView.setOnClickListener(new OnClickListener() &#123;</span><br><span class="line">			</span><br><span class="line">			@Override</span><br><span class="line">			public void onClick(View v) &#123;</span><br><span class="line">				startAPP(appInfos.get(position).getAppPackage());</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;);</span><br><span class="line">		return convertView;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	public class Holder&#123;</span><br><span class="line">		ImageView icon;</span><br><span class="line">		TextView name;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	public void startAPP(String appPackageName)&#123;</span><br><span class="line">	    try&#123;</span><br><span class="line">	        Intent intent &#x3D; mContext.getPackageManager().getLaunchIntentForPackage(appPackageName);</span><br><span class="line">	        mContext.startActivity(intent);</span><br><span class="line">	    &#125;catch(Exception e)&#123;</span><br><span class="line">	    	e.printStackTrace();</span><br><span class="line">	    &#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li><strong>gridview_item.xml</strong><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;RelativeLayout xmlns:android&#x3D;&quot;http:&#x2F;&#x2F;schemas.android.com&#x2F;apk&#x2F;res&#x2F;android&quot;</span><br><span class="line">    android:layout_width&#x3D;&quot;110dp&quot;</span><br><span class="line">    android:layout_height&#x3D;&quot;wrap_content&quot; &gt;</span><br><span class="line"></span><br><span class="line">    &lt;ImageView</span><br><span class="line">        android:id&#x3D;&quot;@+id&#x2F;imageView1&quot;</span><br><span class="line">        android:layout_width&#x3D;&quot;100dp&quot;</span><br><span class="line">        android:layout_height&#x3D;&quot;100dp&quot;</span><br><span class="line">        android:src&#x3D;&quot;@drawable&#x2F;ic_launcher&quot; &#x2F;&gt;</span><br><span class="line">    </span><br><span class="line">    &lt;TextView</span><br><span class="line">        android:id&#x3D;&quot;@+id&#x2F;textview1&quot;</span><br><span class="line">        android:layout_width&#x3D;&quot;wrap_content&quot;</span><br><span class="line">        android:layout_height&#x3D;&quot;wrap_content&quot;</span><br><span class="line">        android:layout_below&#x3D;&quot;@+id&#x2F;imageView1&quot;</span><br><span class="line">        android:text&#x3D;&quot;textview1&quot;</span><br><span class="line">        android:maxLines&#x3D;&quot;1&quot;</span><br><span class="line">        android:textSize&#x3D;&quot;10sp&quot;</span><br><span class="line">        android:textColor&#x3D;&quot;#ffffff&quot;</span><br><span class="line">        android:layout_centerHorizontal&#x3D;&quot;true&quot;&#x2F;&gt;</span><br><span class="line">    </span><br><span class="line">&lt;&#x2F;RelativeLayout&gt;</span><br></pre></td></tr></table></figure></li>
<li><strong>AndroidManifest.xml</strong></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">&lt;manifest xmlns:android&#x3D;&quot;http:&#x2F;&#x2F;schemas.android.com&#x2F;apk&#x2F;res&#x2F;android&quot;</span><br><span class="line">    package&#x3D;&quot;com.example.gridviewstudy&quot;</span><br><span class="line">    android:versionCode&#x3D;&quot;1&quot;</span><br><span class="line">    android:versionName&#x3D;&quot;1.0&quot; &gt;</span><br><span class="line"></span><br><span class="line">    &lt;uses-sdk</span><br><span class="line">        android:minSdkVersion&#x3D;&quot;8&quot;</span><br><span class="line">        android:targetSdkVersion&#x3D;&quot;21&quot; &#x2F;&gt;</span><br><span class="line"></span><br><span class="line">    &lt;application</span><br><span class="line">        android:allowBackup&#x3D;&quot;true&quot;</span><br><span class="line">        android:icon&#x3D;&quot;@drawable&#x2F;ic_launcher&quot;</span><br><span class="line">        android:label&#x3D;&quot;@string&#x2F;app_name&quot;</span><br><span class="line">        android:theme&#x3D;&quot;@style&#x2F;AppTheme&quot; &gt;</span><br><span class="line">        &lt;activity android:name&#x3D;&quot;cccc.cccc.HomeActivity&quot;&gt;</span><br><span class="line">            &lt;intent-filter&gt;</span><br><span class="line">                &lt;action android:name&#x3D;&quot;android.intent.action.MAIN&quot;&#x2F;&gt;</span><br><span class="line">                &lt;category android:name&#x3D;&quot;android.intent.category.LAUNCHER&quot;&#x2F;&gt;</span><br><span class="line">            &lt;&#x2F;intent-filter&gt;</span><br><span class="line">        &lt;&#x2F;activity&gt;</span><br><span class="line">    &lt;&#x2F;application&gt;</span><br><span class="line"></span><br><span class="line">&lt;&#x2F;manifest&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
      </div>
      
        <div class="prev-or-next">
          <div class="post-foot-next">
            
              <a href="/2020/12/23/Quick-Chip/" target="_self">
                <i class="iconfont icon-chevronleft"></i>
                <span>Prev</span>
              </a>
            
          </div>
          <div class="post-attach">
            <span class="post-pubtime">
              <i class="iconfont icon-updatetime" title="Update time"></i>
              2020-12-23
            </span>
            
                  <span class="post-tags">
                    <i class="iconfont icon-tags" title="Tags"></i>
                    
                    <span class="span--tag">
                      <a href="/tags/Android/" title="Android">
                        <b>#</b> Android
                      </a>
                    </span>
                    
                    <span class="span--tag">
                      <a href="/tags/GridView/" title="GridView">
                        <b>#</b> GridView
                      </a>
                    </span>
                    
                  </span>
              
          </div>
          <div class="post-foot-prev">
            
              <a href="/2020/12/23/Terminal-Capabilities-9F33/" target="_self">
                <span>Next</span>
                <i class="iconfont icon-chevronright"></i>
              </a>
            
          </div>
        </div>
      
    </div>
    

    
      <div class="comments-container">
        




  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
  <script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>

  <div id="gitalk-container"></div>
  <script src="/js/md5.min.js"></script>
  <script>
    const gitalk = new Gitalk({
      clientID: '57cd3399b19f860fecc9',
      clientSecret: '2190b5d0de9a59b3de639f23ad0b771ead37dcca',
      repo: 'longxiying.github.io',
      owner: 'longxiying',
      admin: ['longxiying'],
      id: md5(location.pathname),
      distractionFreeMode: false
    })

    gitalk.render('gitalk-container')
  </script>


      </div>
    
  </div>


        <div class="footer">
  <div class="social">
    <ul>
      
        <li>
          <a title="github" target="_blank" rel="noopener" href="https://github.com/longxiying">
            <i class="iconfont icon-github"></i>
          </a>
        </li>
      
        <li>
          <a title="email" href="mailto:longxiying@vip.qq.com">
            <i class="iconfont icon-envelope"></i>
          </a>
        </li>
      
        <li>
          <a title="facebook" target="_blank" rel="noopener" href="https://www.facebook.com/abtswiath/">
            <i class="iconfont icon-facebooksquare"></i>
          </a>
        </li>
      
        <li>
          <a title="twitter" target="_blank" rel="noopener" href="https://twitter.com/longxiying">
            <i class="iconfont icon-twitter"></i>
          </a>
        </li>
      
        <li>
          <a title="wechat" href="">
            <i class="iconfont icon-wechat"></i>
          </a>
        </li>
      
        <li>
          <a title="weibo" target="_blank" rel="noopener" href="https://weibo.com/579081111/">
            <i class="iconfont icon-weibo"></i>
          </a>
        </li>
      
        <li>
          <a title="rss" href="/atom.xml">
            <i class="iconfont icon-rss"></i>
          </a>
        </li>
      
    </ul>
  </div>
  
    <div class="footer-more">
      
        <a href="https://emv.cool">Copyright © EMV.COOL 2020</a>
        
    </div>
  
    <div class="footer-more">
      
        <a target="_blank" rel="noopener" href="https://github.com/zchengsite/hexo-theme-oranges">Theme by Oranges | Powered by Hexo</a>
        
    </div>
  
</div>

      </div>

      <div class="back-to-top hidden">
  <a href="javascript: void(0)">
    <i class="iconfont icon-chevronup"></i>
  </a>
</div>


<script src="/js/backtotop.js"></script>



      
  <div class="search-icon" id="search-icon">
    <a href="javascript: void(0)">
      <i class="iconfont icon-search"></i>
    </a>
  </div>

  <div class="search-overlay hidden">
    <div class="search-content" tabindex="0">
      <div class="search-title">
        <span class="search-icon-input">
          <a href="javascript: void(0)">
            <i class="iconfont icon-search"></i>
          </a>
        </span>
        
          <input type="text" class="search-input" id="search-input" placeholder="Search...">
        
        <span class="search-close-icon" id="search-close-icon">
          <a href="javascript: void(0)">
            <i class="iconfont icon-close"></i>
          </a>
        </span>
      </div>
      <div class="search-result" id="search-result"></div>
    </div>
  </div>

  <script type="text/javascript">
    var inputArea = document.querySelector("#search-input")
    var searchOverlayArea = document.querySelector(".search-overlay")

    inputArea.onclick = function() {
      getSearchFile()
      this.onclick = null
    }

    inputArea.onkeydown = function() {
      if(event.keyCode == 13)
        return false
    }

    function openOrHideSearchContent() {
      let isHidden = searchOverlayArea.classList.contains('hidden')
      if (isHidden) {
        searchOverlayArea.classList.remove('hidden')
        document.body.classList.add('hidden')
        // inputArea.focus()
      } else {
        searchOverlayArea.classList.add('hidden')
        document.body.classList.remove('hidden')
      }
    }

    function blurSearchContent(e) {
      if (e.target === searchOverlayArea) {
        openOrHideSearchContent()
      }
    }

    document.querySelector("#search-icon").addEventListener("click", openOrHideSearchContent, false)
    document.querySelector("#search-close-icon").addEventListener("click", openOrHideSearchContent, false)
    searchOverlayArea.addEventListener("click", blurSearchContent, false)

    var searchFunc = function (path, search_id, content_id) {
      'use strict';
      var $input = document.getElementById(search_id);
      var $resultContent = document.getElementById(content_id);
      $resultContent.innerHTML = "<ul><span class='local-search-empty'>First search, index file loading, please wait...<span></ul>";
      $.ajax({
        // 0x01. load xml file
        url: path,
        dataType: "xml",
        success: function (xmlResponse) {
          // 0x02. parse xml file
          var datas = $("entry", xmlResponse).map(function () {
            return {
              title: $("title", this).text(),
              content: $("content", this).text(),
              url: $("url", this).text()
            };
          }).get();
          $resultContent.innerHTML = "";

          $input.addEventListener('input', function () {
            // 0x03. parse query to keywords list
            var str = '<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length <= 0) {
              return;
            }
            // 0x04. perform local searching
            datas.forEach(function (data) {
              var isMatch = true;
              var content_index = [];
              if (!data.title || data.title.trim() === '') {
                data.title = "Untitled";
              }
              var orig_data_title = data.title.trim();
              var data_title = orig_data_title.toLowerCase();
              var orig_data_content = data.content.trim().replace(/<[^>]+>/g, "");
              var data_content = orig_data_content.toLowerCase();
              var data_url = data.url;
              var index_title = -1;
              var index_content = -1;
              var first_occur = -1;
              // only match artiles with not empty contents
              if (data_content !== '') {
                keywords.forEach(function (keyword, i) {
                  index_title = data_title.indexOf(keyword);
                  index_content = data_content.indexOf(keyword);

                  if (index_title < 0 && index_content < 0) {
                    isMatch = false;
                  } else {
                    if (index_content < 0) {
                      index_content = 0;
                    }
                    if (i == 0) {
                      first_occur = index_content;
                    }
                    // content_index.push({index_content:index_content, keyword_len:keyword_len});
                  }
                });
              } else {
                isMatch = false;
              }
              // 0x05. show search results
              if (isMatch) {
                str += "<li><a href='" + data_url + "' class='search-result-title'>" + orig_data_title + "</a>";
                var content = orig_data_content;
                if (first_occur >= 0) {
                  // cut out 100 characters
                  var start = first_occur - 20;
                  var end = first_occur + 80;

                  if (start < 0) {
                    start = 0;
                  }

                  if (start == 0) {
                    end = 100;
                  }

                  if (end > content.length) {
                    end = content.length;
                  }

                  var match_content = content.substr(start, end);

                  // highlight all keywords
                  keywords.forEach(function (keyword) {
                    var regS = new RegExp(keyword, "gi");
                    match_content = match_content.replace(regS, "<span class=\"search-keyword\">" + keyword + "</span>");
                  });

                  str += "<p class=\"search-result-abstract\">" + match_content + "...</p>"
                }
                str += "</li>";
              }
            });
            str += "</ul>";
            if (str.indexOf('<li>') === -1) {
              return $resultContent.innerHTML = "<ul><span class='local-search-empty'>No result<span></ul>";
            }
            $resultContent.innerHTML = str;
          });
        },
        error: function(xhr, status, error) {
          $resultContent.innerHTML = ""
          if (xhr.status === 404) {
            $resultContent.innerHTML = "<ul><span class='local-search-empty'>The search.xml file was not found, please refer to：<a href='https://github.com/zchengsite/hexo-theme-oranges#configuration' target='_black'>configuration</a><span></ul>";
          } else {
            $resultContent.innerHTML = "<ul><span class='local-search-empty'>The request failed, Try to refresh the page or try again later.<span></ul>";
          }
        }
      });
      $(document).on('click', '#search-close-icon', function() {
        $('#search-input').val('');
        $('#search-result').html('');
      });
    }

    var getSearchFile = function() {
        var path = "/search.xml";
        searchFunc(path, 'search-input', 'search-result');
    }
  </script>




    </div>
  </body>
</html>
